// CPUTest.cpp: implementation of the CPUTest class.
//
//////////////////////////////////////////////////////////////////////

#include "CPUTest.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CPUTest::CPUTest()
{
this->total_t				= 0.0f;

this->physics_t             = 0.0f;
this->physics_dt			= 0.0f;

this->database_t            = 0.0f;
this->database_dt           = 0.0f;

this->graphics_t            = 0.0f;
this->graphics_dt			= 0.0f;

this->input_t				= 0.0f;
this->input_dt				= 0.0f;
}

CPUTest::~CPUTest()
{

}

void CPUTest::testPhysics(int c)
{
if(c == CPUTEST_START)
	{
	this->physics_ck . update () ;
	}
else
	{
	this->physics_ck . update () ;
	this->physics_dt = (float)this->physics_ck . getDeltaTime () ;
	this->physics_t += this->physics_dt;
	this->total_t += this->physics_dt;
	}
}

void CPUTest::testGraphics(int c)
{
if(c == CPUTEST_START)
	{
	this->graphics_ck . update () ;
	}
else
	{
	this->graphics_ck . update () ;
	this->graphics_dt = (float)this->graphics_ck . getDeltaTime () ;
	this->graphics_t += this->graphics_dt;
	this->total_t += this->graphics_dt;
	}
}

void CPUTest::testDatabase(int c)
{
if(c == CPUTEST_START)
	{
	this->database_ck . update () ;
	}
else
	{
	this->database_ck . update () ;
	this->database_dt = (float)this->database_ck . getDeltaTime () ;
	this->database_t += this->database_dt;
	this->total_t += this->database_dt;
	}
}

void CPUTest::testInput(int c)
{
if(c == CPUTEST_START)
	{
	this->input_ck . update () ;
	}
else
	{
	this->input_ck . update () ;
	this->input_dt = (float)this->input_ck . getDeltaTime () ;
	this->input_t += this->input_dt;
	this->total_t += this->input_dt;
	}
}

void CPUTest::printCPUusage()
{
printf("\t\t\t\tCPU USAGE\n");
printf("\t\t\t\t---------\n");
printf("INPUT  \t\t%.3f  %.2f%%\n",this->input_t,this->input_t / this->total_t * 100.0f);
printf("PHYSICS\t\t%.3f  %.2f%%\n",this->physics_t,this->physics_t / this->total_t * 100.0f);
printf("DATABASE\t%.3f  %.2f%%\n",this->database_t,this->database_t / this->total_t * 100.0f);
printf("GRAPHICS\t%.3f  %.2f%%\n",this->graphics_t,this->graphics_t / this->total_t * 100.0f);
printf("Total:\t\t%.3f %.2f%%\n",this->total_t,100.0f);
}